﻿using System;
using System.Collections.Generic;
using System.Text;
using SdmxMl.Common;

namespace SdmxMl.Helper
{
    public sealed class RefHelper
    {
        /// <summary>
        /// Check if reference is valid or incomplete.
        /// No version means a version of 1.0 so not part of check.
        /// </summary>
        /// <param name="ar">The reference info</param>
        /// <returns>True if valid (filled correctly)</returns>
        public static bool IsFilled(ISdmxArtefactRef ar)
        {
            if (ar != null &&
                string.IsNullOrEmpty(ar.Id) == false &&
                string.IsNullOrEmpty(ar.AgencyId) == false)
                return true;

            return false;
        }

        public static bool SameReference(ISdmxArtefactRef arl, ISdmxArtefactRef arr)
        {
            bool same = false;
            
            //Invalid ref considered as not same
            if (IsFilled(arl) && IsFilled(arr))
            {
                same = arl.Id == arr.Id && 
                    arl.AgencyId == arr.AgencyId &&
                    arl.Version == arr.Version;
            }
            return same;
        }


    }
}
